<template>
  <div>
    <el-pagination
      background
      :current-page="query.page"
      :page-sizes="[2,5, 10, 15, 20]"
      :page-size="query.pagesize"
      layout="prev, pager, next, sizes, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
export default {
  name: 'QuestionsPagination',
  props: {
    total: {
      type: [Number, String],
      default () {
      }
    }
  },
  data () {
    return {
      // 分页数据
      query: {
        page: 1, // 当前页
        pagesize: 5 // 当前页显示多少条
      }
    }
  },
  methods: {
    // 当前页显示条数改变触发
    handleSizeChange (newPagesize) {
      this.query.pagesize = newPagesize
      this.$emit('query', this.query)
    },
    // 当前页数改变触发
    handleCurrentChange (newPage) {
      this.query.page = newPage
      this.$emit('query', this.query)
    }
  }
}
</script>

<style scoped>
.el-pagination {
  text-align: end;
  margin-top: 20px;
}
</style>
